<?php

namespace app\admin\service;

use app\admin\model\Pickuppoint as PickuppointMdl;

use think\Db;
use think\Exception;

class Pickuppoint
{

    /**
     * 导出数据
     */
    public static function export($request){
        $param = $request->param();

        $where = [
            'status' => 1,
        ];

        $model = new PickuppointMdl();
        $data = $model->where($where)->order('create_date', 'asc')->select();
        if(count($data) <= 0){
            return [
                'code' => 2,
                'msg' => '没有数据！'
            ];
        }

        /*foreach ($data as $key => $val) {
            // 是否启用
            switch ($val['status']) {
                case 1: $val['status'] = '启用'; break;
                case 2: $val['status'] = '禁用'; break;
                default : $val['status'] = '禁用'; break;
            }
        }*/

        $cellName = array(
            'A' => ['id', '序号'],
            'B' => ['name', '提货点'],
            'C' => ['region', '所在城市'],
            'D' => ['business_start_time', '营业开始时间'],
            'E' => ['business_end_time', '营业结束时间'],
            'F' => ['address', '地址'],
            'G' => ['person', '联系人'],
            'H' => ['phone', '手机号'],
        );

        $filePath = ROOT_PATH . 'public' . DS . 'upload' . DS . 'csv' . DS . 'pickuppoint' . DS . date('Y-m-d');
        $fileName = $filePath . '/pickuppoint_' . date('y-m-d-H-i-s');

        $excel = new Excel();
        $excel::exportExcel('提货点', $data, $cellName, $filePath, $fileName);

        return [
            'code' => 1,
            'msg' => '导出成功！'
        ];
    }

}